﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Build Log</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(to right, #eef2f3, #8e9eab);
            margin: 0;
            padding: 20px;
            color: #333;
        }

        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }

        .log-container {
            background-color: #ffffffdd;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            padding: 20px;
            margin: auto;
            max-width: 900px;
            margin-bottom: 15px;
        }

        .time-header {
            text-align: center;
            font-size: 18px;
            margin: 20px 0 10px;
            color: #777;
            font-weight: bold;
        }

        .log-item {
            margin-bottom: 15px;
        }

        .label {
            display: inline-block;
            font-weight: 700;
            color: #2c3e50;
            min-width: 124px;
            margin-right: 10px;
        }

        .export {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
            padding: 10px 20px;
            font-size: 16px;
            background-color: #007acc;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        pre {
            background-color: #2d2d2d;
            color: #f8f8f2;
            padding: 20px;
            border-left: 5px solid #6272a4;
            white-space: pre-wrap;
            word-wrap: break-word;
            font-size: 18px;
            overflow-x: auto;
            border-radius: 6px;
            line-height: 28px;
        }

        .login-container {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999;
        }

        .login-box {
            background-color: #fff;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
            max-width: 400px;
            width: 100%;
            text-align: center;
            animation: fadeIn 0.5s ease-in-out;
            margin: 150px auto;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .input-group {
            margin-bottom: 20px;
            text-align: left;
        }

        .input-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 8px;
            color: #333;
        }

        .input-group input {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ccc;
            border-radius: 6px;
            font-size: 14px;
            box-sizing: border-box;
        }

        .login-btn {
            width: 100%;
            padding: 12px;
            background-color: #007acc;
            color: white;
            font-size: 16px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .login-btn:hover {
            background-color: #005fa3;
        }

        hr {
            border: none;
            border-top: 1px solid #ddd;
            margin: 15px 0;
        }

        @media (max-width: 600px) {
            .label {
                display: block;
                margin-bottom: 4px;
            }
        }
    </style>
</head>
<body>
    <div id="login-form" class="login-container">
        <div class="login-box">
            <h2>访问控制</h2>
            <form id="loginForm">
                <div class="input-group">
                    <label for="username">用户名</label>
                    <input type="text" id="username" placeholder="请输入用户名" required />
                </div>

                <div class="input-group">
                    <label for="password">密码</label>
                    <input type="password" id="password" placeholder="请输入密码" required />
                </div>

                <button type="submit" class="login-btn">登录</button>
            </form>
        </div>
    </div>

    <div id="content" style="display:none;">
        <button class="export" onclick="window.print()">导出为 PDF</button>
        <h1>_BUILDLOGNAME_</h1>
        <div id="logList"></div>
    </div>

    <!-- 存放加密内容 -->
    <script id="encryptedData" type="application/json">
        __ENCRYPTED_CONTENT_PLACEHOLDER__
    </script>

    <!-- 引入 CryptoJS 库 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function (event) {
            event.preventDefault();
            login(event);
        });
        const validUser = "__VALID_USER_PLACEHOLDER__";
        const validPassHash = "__VALID_PASS_HASH_PLACEHOLDER__";
        const TOKEN_KEY = "dev_access_token";
        const EXPIRE_TIME_KEY = "dev_access_expire";
        async function login(event) {
            event.preventDefault();
            const user = document.getElementById('username').value;
            const pass = document.getElementById('password').value;
            const userhash = await sha256(user);
            if (userhash === validUser) {
                const passhash = await sha256(pass);
                if (passhash === validPassHash) {
                    const now = Date.now();
                    const sevenDaysLater = now + 7 * 24 * 60 * 60 * 1000;
                    localStorage.setItem(TOKEN_KEY, validPassHash);
                    localStorage.setItem(EXPIRE_TIME_KEY, sevenDaysLater.toString());

                    decryptAndRender();
                } else {
                    alert("密码错误！");
                }
            } else {
                alert("用户名错误！");
            }
        }

        function sha256(s) {
            const encoder = new TextEncoder();
            return crypto.subtle.digest("SHA-256", encoder.encode(s)).then(buf => {
                return Array.prototype.map.call(new Uint8Array(buf), x => ('00' + x.toString(16)).slice(-2)).join('');
            });
        }

        function decryptAndRender() {
            const encrypted = document.getElementById('encryptedData').innerText.trim();

            const key = CryptoJS.enc.Utf8.parse("__AES_KEY_PLACEHOLDER__");
            const iv = CryptoJS.enc.Utf8.parse("__AES_IV_PLACEHOLDER__");

            let decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv });
            let originalHtml = decrypted.toString(CryptoJS.enc.Utf8);

            document.getElementById('login-form').style.display = 'none';
            document.getElementById('logList').innerHTML = originalHtml;
            document.getElementById('content').style.display = 'block';
        }

        window.onload = function () {
            const storedToken = localStorage.getItem(TOKEN_KEY);
            const expireTime = localStorage.getItem(EXPIRE_TIME_KEY);
            const validToken = "__VALID_TOKEN_PLACEHOLDER__";
            if (storedToken === validPassHash && expireTime && Date.now() < parseInt(expireTime)) {
                decryptAndRender();
            }
            else {
                if (validToken === validPassHash) {
                    decryptAndRender();
                }
                else{
                    document.getElementById('login-form').style.display = 'block';
                }
            }
        };
    </script>
</body>
</html>
